package com.weasel.im.common.service.impl;

import com.google.common.collect.Maps;
import com.weasel.im.common.service.UserSessionRelation;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Dylan on 2015/12/1.
 */
public class DefaultUserSessionRelationImpl implements UserSessionRelation {

    private Map<String,String> usernameToSessionid = new HashMap<String, String>();
    private Map<String,String>sessionidToUsername = new HashMap<String, String>();

    public void relation(String username, String sessionid) {

        String oldSessionid = usernameToSessionid.get(username);
        usernameToSessionid.put(username,sessionid);
        sessionidToUsername.put(sessionid, username);
        sessionidToUsername.remove(oldSessionid);
    }

    public String getUsernameBySessionid(String sessionid) {
        return sessionidToUsername.get(sessionid);
    }

    public String getSessionidByUsername(String username) {
        return usernameToSessionid.get(username);
    }

}
